package dimension.starry.key;

import dimension.starry.StarryDimension;
import dimension.starry.gui.screen.PlayerInfoScreen;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;

public class KeybindingRegisterManager {

    public static final KeyBinding SKILL_KEY1 = new KeyBinding(
        "key." + StarryDimension.MOD_ID + ".skill.1", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_Z,
        "key.category." + StarryDimension.MOD_ID);
    public static final KeyBinding SKILL_KEY2 = new KeyBinding(
        "key." + StarryDimension.MOD_ID + ".skill.2", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_V,
        "key.category." + StarryDimension.MOD_ID);
    public static final KeyBinding SKILL_KEY3 = new KeyBinding(
        "key." + StarryDimension.MOD_ID + ".skill.3", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_B,
        "key.category." + StarryDimension.MOD_ID
    );
    public static final KeyBinding MAIN_MENU = new KeyBinding(
        "key." + StarryDimension.MOD_ID + ".menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C,
        "key.category." + StarryDimension.MOD_ID
    );

    public static void onInitializeClient() {
        KeyBindingHelper.registerKeyBinding(SKILL_KEY1);
        KeyBindingHelper.registerKeyBinding(SKILL_KEY2);
        KeyBindingHelper.registerKeyBinding(SKILL_KEY3);
        KeyBindingHelper.registerKeyBinding(MAIN_MENU);

        registerListener();
    }

    private static void registerListener() {
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            if (MAIN_MENU.wasPressed()) {
                MinecraftClient.getInstance().setScreenAndRender(new PlayerInfoScreen());
            }
        });
    }

}
